package com.shansun.easitest.pamirs;

import org.junit.runner.notification.RunNotifier;
import org.junit.runners.model.FrameworkMethod;

import com.shansun.easitest.exception.EasiException;
import com.shansun.easitest.junit.EasiJUnitClassRunner;

@SuppressWarnings("rawtypes")
public class PamirsJUnitClassRunner extends EasiJUnitClassRunner {

	@SuppressWarnings("unchecked")
	public PamirsJUnitClassRunner(Class klass) throws Exception {
		super(klass);
	}

	protected void runChild(final FrameworkMethod method, final RunNotifier notifier) {
		InnerPamirsTransactionTemplate pamirsTransactionTemplate = (InnerPamirsTransactionTemplate) getBeanFactory().getBean("innerPamirsTransactionTemplate");
		try {
			pamirsTransactionTemplate.execute(new InnerPamirsTransactionAction() {

				@Override
				public Object doInTransaction(InnerPamirsTransactionStatus arg0) throws Exception {
					innerRunChild(method, notifier);
					throw new EasiException();
				}
			});
		} catch (Exception e) {
			if (!(e.getCause() instanceof EasiException)) {
				throw new RuntimeException(e);
			}
		}
	}

	protected void innerRunChild(final FrameworkMethod method, final RunNotifier notifier) {
		super.runChild(method, notifier);
	}
}
